
var app = require('express')();
var server  = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(7999, ()=>{
    console.log('chat app listening: 7999');
});

app.get('/chat', function (req, res) {
    
});

io.on('connection', function (socket) {
    console.log('new connection');

    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
        console.log(data);
    });
    socket.on('chatPrompt', data=>{
        console.log(data);
        socket.emit('hello', 'hello!')
    });
    socket.on('send', data=>{
        console.log(data);
        socket.emit('update chat', {msg:data});
    })

    socket.on('disconnect', function(){
        console.log('user disconnected');
    });
});

module.exports = io;